package com.yitiao.socket.server;

import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;

import java.io.InputStream;
import java.util.Arrays;

@RequiredArgsConstructor
@Data
public class Request {

    public static final int BUFFER_SIZE = 1024;

    private final InputStream inputStream;

    private String uri;

    @SneakyThrows
    public void parse(){
        byte[] buffer = new byte[BUFFER_SIZE];
        int read = inputStream.read(buffer);
        String request = Arrays.toString(buffer);
        uri = parseUri(request);
    }

    private String parseUri(String request) {
        String[] split = request.split(" ");
        if (split.length>2){
            return split[1];
        }
        return "";
    }
}
